<template>
  <div class="content">
    <Form :label-width="160" :model="datas" ref="form" showErrorTip>
      <FormItem label="授权发起页域名" prop="number">
        <div class="h-input-group" v-width="500">
          <input type="text" readonly v-model="datas.authorizesurl" />
          <Button color="gray" @click="handleCopyData(datas.authorizesurl)">复制</Button>
        </div>
      </FormItem>
      <FormItem label="授权事件接收URL" prop="mobile">
        <div class="h-input-group" v-width="500">
          <input type="text" readonly v-model="datas.ticketurl" />
          <Button color="gray">复制</Button>
        </div>
      </FormItem>
      <FormItem label="消息校验Token" prop="mobile">
        <div class="h-input-group" v-width="500">
          <input type="text" v-model="datas.token" />
          <Button color="green" @click="handleResetData('token',28)">重置</Button>
        </div>
      </FormItem>
      <FormItem label="消息加解密Key" prop="mobile">
        <div class="h-input-group" v-width="500">
          <input type="text" v-model="datas.encodingaeskey" />
          <Button color="green" @click="handleResetData('encodingaeskey',43)">重置</Button>
        </div>
      </FormItem>
      <FormItem label="消息与事件接收URL" prop="mobile">
        <div class="h-input-group" v-width="500">
          <input type="text" readonly v-model="datas.receivingurl" />
          <Button color="gray">复制</Button>
        </div>
      </FormItem>
      <FormItem label="公众号开发域名" prop="mobile">
        <div class="h-input-group" v-width="500">
          <input type="text" readonly v-model="datas.developmenturl" />
          <Button color="gray">复制</Button>
        </div>
      </FormItem>
    </Form>
  </div>
</template>
<script type="text/javascript">
// import empty from './empty.vue'
export default {
  components: {
    // empty
  },
  data() {
    return {
      datas: {
        authorizesurl: "",
        ticketurl: "",
        token: "",
        receivingurl: "",
        encodingaeskey: "",
        developmenturl: ""
      }
    };
  },
  /**
   * 计算属性
   * @type {Object}
   */
  computed: {

  },
  /**
   * 页面渲染前
   * @return {[type]} [description]
   */
  created() {

  },
  /**
   * 数据监听
   * @type {Object}
   */
  watch: {

  },
  /**
   * 页面加载执行
   * @return {[type]} [description]
   */
  async mounted() {
    this.handleApplyInfo();
  },
  methods: {
    affirm(e) {
      let { handleCancel } = e;
      handleCancel();
    },
    /**
     * 拷贝数据
     * @param  {[type]} value [description]
     * @return {[type]}       [description]
     */
    handleCopyData(value) {
      this.$Clipboard({
        text: value,
        showSuccessTip: '已复制到剪切板'
      });
    },
    /**
     * 基础信息
     * @return {[type]} [description]
     */
    handleApplyInfo() {
      this.datas.authorizesurl = /^http(s)?:\/\/(.*?)\//.exec(this.$cloud.AppURL + "/")[2];
      this.datas.developmenturl = /^http(s)?:\/\/(.*?)\//.exec(this.$cloud.AppURL + "/")[2];
      this.datas.ticketurl = this.$cloud.AppURL + "/" + this.$cloud.AppID + "/wechat/service/ticket";
      this.datas.receivingurl = this.$cloud.AppURL + "/" + this.$cloud.AppID + "/wechat/service/$APPID$";
      this.datas.token = this.handleRandomChar(28);
      this.datas.encodingaeskey = this.handleRandomChar(43);

    },
    /**
     * 重置数据
     * @return {[type]} [description]
     */
    handleResetData(key, lang) {

    },
    /**
     * 随机字符串
     * @param  {[type]} l [description]
     * @return {[type]}   [description]
     */
    handleRandomChar(l) {
      let x = "0123456789qwertyuioplkjhgfdsazxcvbnm";
      let tmp = "";
      let timestamp = new Date().getTime();
      for (let i = 0; i < l; i++) {
        tmp += x.charAt(Math.ceil(Math.random() * 100000000) % x.length);
      }
      return tmp;
    }
  }
}

</script>
<style lang="less" scoped="true">
</style>
